package leetcode100;

public class lc039 {
    public static void main(String[] args) {
        int[] nums = {3,2,1,0,4};

        boolean b = new lc039().canJump(nums);
        System.out.println("b = " + b);
    }


    public boolean canJump(int[] nums) {
        int currrentReach=0;
        int maxReach = 0;

        for (int i = 0; i <= maxReach; i++) {
//            System.out.println("i = " + i);
            currrentReach = i+nums[i];
//            System.out.println("currrentReach = " + currrentReach);
            maxReach = Math.max(currrentReach,maxReach);
//            System.out.println("maxReach = " + maxReach);
            if (maxReach>=nums.length-1) {
                return true;
            }
        }
        return false;

    }
}
